package com.maxlen.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maxlen.admin.entity.AdminRole;
import com.maxlen.admin.mapper.AdminRoleMapper;
import com.maxlen.admin.service.IAdminRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-10-11
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {

    @Override
    @Transactional
    public void removeByRoleId(Long id) {
        baseMapper.delete(new LambdaQueryWrapper<AdminRole>().eq(AdminRole::getRoleId, id));
    }

    @Override
    @Transactional
    public void addByRoleIdList(Long id, List<Long> roleId) {
        for (Long num : roleId) {
            baseMapper.insert(new AdminRole(id, num));
        }
    }

    @Override
    @Transactional
    public void removeByAdminId(Long id) {
        baseMapper.delete(new LambdaQueryWrapper<AdminRole>().eq(AdminRole::getAdminId, id));
    }

    @Override
    @Transactional
    public void removeByAdminIdRoleId(Long adminId, Long roleId) {
        baseMapper.delete(new LambdaQueryWrapper<AdminRole>().eq(AdminRole::getAdminId, adminId).eq(AdminRole::getRoleId, roleId));
    }
}
